# 子类默认继承父类的所有属性和方法
# # 父类
# class A(object):
#     def __init__(self):
#         self.num = 1
#     def info_print(self):
#         print(self.num)
# # 子类
# class B(A):
#     pass
# result = B()
# result.info_print() # 1


# 练习单继承，煎饼果子
# class Master():
#     def __init__(self):
#         self.peifang = '五香'
#     def make(self):
#         print(f'制作{self.peifang}煎饼果子')
# class son(Master):
#     pass
# 实例化子类，使用父类的方法
# ming = son()
# ming.make()

# 多继承:当一个类有多个父类的时候，默认使用第一个父类的属性和方法，无法继承第二个父类和方法
# class school():
#     def __init__(self):
#         self.pei = '香辣'
#     def make1(self):
#         print(f'制作{self.pei}煎饼果子')
# class son(school,Master):
#     pass
# hong = son()
# hong.make1()


# 重写:子类和父类公用同一个属性和方法的时候，默认调用子类的属性和方法,子类也可以添加新的属性和方法
# class Master():
#     def __init__(self):
#         self.peifang = '五香'
#     def make(self):
#         print(f'制作{self.peifang}煎饼果子')
# class son(Master):
#     def __init__(self):
#         self.peifang = '孜然'
#     def make(self):
#         print(f'制作{self.peifang}煎饼果子')
# class sun(Master):
#     def __init__(self):
#         self.pei='臭豆腐'
#     def mmake(self):
#         print(f'制作{self.pei}煎饼果子')
# gang = son()
# liu=sun()
# liu.mmake()
# gang.make()


# 子类调用父类的属性和方法
# class Master(object):
#     def __init__(self):
#         self.kongfu = '[五香]'
#     def make_cake(self):
#         print(f'{self.kongfu}')
# class School(object):
#     def __init__(self):
#         self.kongfu = '[香辣]'
#     def make_cake(self):
#         print(f'{self.kongfu}')
# class Prentice(School, Master):
#     def __init__(self):
#         self.kongfu = '[臭豆腐]'
#     def make_cake(self):
#         self.__init__()  #这句话的意思是，执行子类方法之前先调用一下子类的属性，防止和父类冲突
#         print(f'{self.kongfu}')
#     def make_master_cake(self):
#         Master.__init__(self)
#         Master.make_cake(self)
#     def make_school_cake(self):
#         School.__init__(self)
#         School.make_cake(self)
# xiaoming = Prentice()
# xiaoming.make_cake()
# xiaoming.make_master_cake()
# xiaoming.make_cake()
# xiaoming.make_school_cake()
# xiaoming.make_cake()
#
# # 多层继承
# class sun(Prentice):
#     pass
# li=sun()
# li.make_cake()
# li.make_master_cake()
# li.make_school_cake()

# # super调用父类方法
# class fu():
#     def __init__(self):
#         self.peifang = '五香'
#     def make(self):
#         print(f'制作{self.peifang}煎饼果子')
# class son(fu):
#     def __init__(self):
#         self.peifang='香辣'
#     def make(self):
#         self.__init__()#作用同上述，重置调用的子类的属性
#         print(f'制作{self.peifang}煎饼果子')
#     def make_fu(self):
#         super().__init__()
#         super().make()
# # 实例化子类，使用父类的方法
# ming = son()
# ming.make()
# ming.make_fu()
# ming.make()

# 私有属性
# class fu():
#     def __init__(self):
#         self.peifang = '五香'
#         self.__pei = '臭豆腐'
#     def make(self):
#         print(f'制作{self.peifang}煎饼果子')
#     def get__makee(self):
#         print(f'制作{self.__pei}煎饼果子')
# class son(fu):
#     def __init__(self):
#         self.peifang='香辣'
#     def make(self):
#         self.__init__()#作用同上述，重置调用的子类的属性
#         print(f'制作{self.peifang}煎饼果子')
#     def make_fu(self):
#         super().__init__()
#         super().make()
# class sun(fu):
#     pass
# ming = son()
# ming.make()
# ming.make_fu()
# ming.make()
# gang = sun()
# gang.make()


# 定义私有属性和方法，一般设置私有属性后必然跟随一个调用私有属性的方法和一个修改私有属性的4方法
# 私有属性定义的时候，前面写上__开头，调用的时候一般以get__，设置的时候一般用set__
# 私有属性和私有方法，只能用本类进行调用，无法继承，但是get/set方法可以被子类调用
class fu():
    def __init__(self):
        self.__pei = '五香'
        self.peifang = 'liuxiang'
    def get__make(self):
        print(f'制作{self.__pei}煎饼果子')
    def set__pei(self,xxx):
        self.__pei = xxx
    def make(self):
        print(f'{self.__pei}')
        print(f'{self.peifang}')
    def __make1(self):
        print('keyima')
class son(fu):
    pass
ming = son()
ming.get__make()
ming.set__pei(5)
ming.get__make()
ming.make()
